package com.xjrsoft.module.oa.controller;


import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.xjrsoft.common.result.Response;
import com.xjrsoft.core.secure.utils.SecureUtil;
import com.xjrsoft.module.oa.entity.XjrOaMessagestatus;
import com.xjrsoft.module.oa.service.IXjrOaMessageService;
import com.xjrsoft.module.oa.service.IXjrOaMessagestatusService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author zwq
 * @since 2021-05-18
 */
@RestController
@RequestMapping("/oa/xjr-oa-message")
@Api(value = "/knowledgetype-manager",tags = "消息推送接口")
public class XjrOaMessageController {


    @Autowired
    private IXjrOaMessageService iXjrOaMessageService;


    @Autowired
    private IXjrOaMessagestatusService iXjrOaMessagestatusService;
    
    @GetMapping
    @ApiOperation(value="查询所有消息")
    public Response getList(){
        return Response.ok(iXjrOaMessageService.getList());
    }

    @PutMapping("/{id}")
    @ApiOperation(value="将单条未读消息改为已读")
    public Response readMessage(@PathVariable String id){
        return Response.status(iXjrOaMessagestatusService.readMessage(id));
    }



    @PutMapping("/readAllMessage/{module}")
    @ApiOperation(value="将所以未读消息改为已读")
    public Response readAllMessage(@PathVariable Integer module) throws Exception {
        return Response.status(iXjrOaMessagestatusService.readAllMessage(module));
    }

    @GetMapping("/unread-count")
    @ApiOperation(value="查询所有未读消息数量")
    public Response unreadCount() {
        String userId = SecureUtil.getUserId();
        return Response.ok(iXjrOaMessagestatusService.unreadCount(userId));
    }
}
